<template>
  <div class='over'>
    <tree :model='functions' :is-click="isClick === false ? isClick : true">
      <span partial>
        <span  :class="{ 'tree-img': isFolder(row), 'tree-span': !isFolder(row) }" v-if="!isClick" >
          <img v-if="isFolder(row)" :src="$parent.$parent.imgSrc" alt="">{{row.data.name}}
        </span>
        <span v-if="isClick" >{{row.data.name}}</span>
        <span v-if="row.data.haslicense && row.data.haslicense !== 'false'" >X</span>
      </span>
    </tree>
  </div>
</template>

<script>
export default {
  props: ['functions', 'userid', 'isClick'],
  title: '左侧树菜单',
  data () {
    return {
      imgSrc: './static/treeset.png'
    }
  },
  ready(){

  },
  methods: {
    open (row) {
      console.log(row)
      console.log(row.data.name)
      console.log(JSON.stringify(row.data))
      //console.log(row.data.link )
      if (row.data.name === '资源管理') {
        this.$parent.changeMain(row.data.id)
        return
      }
      if (this.$parent.routeName === 'main') {
        if (row.data.link) {
          this.$goto(row.data.link, {data: row.data, userid: this.userid}, 'main')
        }
      }else {
        if (row.data.resourcetype) {
          //为修改用户传值
          let parent = this.functions
          delete parent.children
          this.$goto(row.data.resourcetype, {data: row.data,parent: parent, userid: this.userid}, 'resmain')
        }
      }
    }
  },
  events: {
    'select-changed': function (data) {
      // 事件回调内的 `this` 自动绑定到注册它的实例上
      this.open(data.val)
      console.log(JSON.stringify(data))
    }
  }
}
</script>
